package com.situ.yB2C.cart.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.situ.yB2C.base.dao.BaseDao;
import com.situ.yB2C.cart.pojo.Cart;

@Repository
public interface CartDao extends BaseDao<Cart> {
	String BASE_SELECT = "SELECT ROW_ID,USER_ID,PRODUCT_ID,ORDER_COUNT,ACTIVE_FLAG,CREATE_BY,CREATE_DATE,UPDATE_BY,UPDATE_DATE FROM TB_CART WHERE ACTIVE_FLAG=1 ";
	String VIEW_BASE_SELECT = "SELECT ROW_ID,USER_ID,PRODUCT_ID,PRODUCT_NAME,MARCKET_PRICE,MEMBER_PRICE,PRODUCT_PICTURE,ORDER_COUNT,ACTIVE_FLAG,CREATE_BY,CREATE_DATE,UPDATE_BY,UPDATE_DATE FROM VI_CART WHERE ACTIVE_FLAG=1 ";

	@Select(BASE_SELECT + " AND USER_ID=${userId}  AND PRODUCT_ID=${productId}")
	Cart selectOnByUserAndPro(@Param("userId") Long userId, @Param("productId") Long productId);

	@Insert("INSERT INTO TB_CART(USER_ID,PRODUCT_ID,ORDER_COUNT,ACTIVE_FLAG,CREATE_BY,CREATE_DATE)VALUES(#{userId},#{productId},#{orderCount},#{activeFlag},#{createBy},#{createDate})")
	int insert(Cart cart);

	@Select(VIEW_BASE_SELECT + " AND USER_ID=#{userId}")
	List<Cart> selectAllByUserId(Long userId);

	@Update("UPDATE TB_CART SET ROW_ID=#{rowId},USER_ID=#{userId},PRODUCT_ID=#{productId},ORDER_COUNT=#{orderCount},ACTIVE_FLAG=#{activeFlag},UPDATE_BY=#{updateBy},UPDATE_DATE=#{updateDate} WHERE ROW_ID=#{rowId}")
	int update(Cart cart);
}
